home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / examples.lha / examples / sds / multi_test / makedata.c next >
Encoding:
C/C++ Source or Header  |  1990-08-24  |  886 b   |  48 lines

  1.  
  2. /*
  3.  *                  make_data.c
  4.  *
  5.  *    A simple routine that writes a data set to be used as
  6.  *    input for multi_test.c
  7.  *      
  8.  *       compile with          cc -o outfile infile.c
  9.  *
  10.  *       Output file: argv[1]: a binary file containing a ROWxCOL
  11.  *                    array of floating point values, with 1's along
  12.  *                    the diagonal and 0's elsewhere.
  13.  */
  14.  
  15. #include <stdio.h>
  16.  
  17. FILE *stream;
  18. #define ROWS 10
  19. #define COLS 10
  20.  
  21. main(argc, argv)
  22. int argc;
  23. char *argv[];
  24. {
  25.  
  26.     int    i, j;
  27.     float    *data_array;
  28.             
  29.     if (argc != 2) {
  30.         printf("Usage: %s <outfile>\n", argv[0]);
  31.         exit(1);
  32.     }
  33.     
  34.     data_array = (float *)malloc(ROWS*COLS*sizeof(float));
  35.     for(i=0;i<ROWS;i++)
  36.     {
  37.        for(j=0;j<COLS;j++)
  38.        {
  39.           *(data_array+i*COLS+j) = (i==j) ? 1.0 : 0; 
  40.        }
  41.     }
  42.  
  43.     stream = fopen(argv[1],"w");
  44.     fwrite(data_array,sizeof(float),ROWS*COLS,stream);
  45.     fclose(stream);
  46.     
  47. }
  48.